package starfield.modpack.web;

import starfield.modpack.web.WebModpack;

public enum SyncingProtocol {
	FTP(21),
	FTPS(990),
	FTPES(21),
	SFTP(22),
	HTTP(80);
	
	private final int port;

	private SyncingProtocol(int port) {
		this.port = port;
	}

	public int getPort() {
		return port;
	}
	
	public static SyncingProtocol valufOfIgnoreCase(String s) {
		SyncingProtocol result = null;
		
		for (SyncingProtocol syncingProtocol : SyncingProtocol.values()) {
			if (syncingProtocol.name().equalsIgnoreCase(s)) {
				if (result == null) {
					result = syncingProtocol;
				} else {
					throw new IllegalArgumentException("Multiple protocols match the given string.");
				}
			}
		}
		
		if (result == null) {
			throw new IllegalArgumentException(s);
		}
		
		return result;
	}
	
	public SyncingTask createSyncingTask(WebModpack modpack, boolean silent) throws SyncingException {
		switch (this) {
			case FTP: return new FTPSyncingTask(modpack, silent, false, false);
			case FTPS: return new FTPSyncingTask(modpack, silent, true, true);
			case FTPES: return new FTPSyncingTask(modpack, silent, true, false);
			case HTTP: return new HTTPSyncingTask(modpack, silent);
			default: throw new SyncingException("Syncing using the '" + name() + "' protocol is not yet possible.");
		}
	}
}
